// pages/me/me.js
Page({
  data: {
    user: {},
    name: '',
    admin: '',
    userType: '',
    doctorId:'',
  },
  onShow() { //拿本地缓存,每一页都需要！！！！！！！！！！！！ 
    var that=this
    let user = wx.getStorageSync('user')
    this.setData({
      user: user,
      name: user && user.name,
      admin: user && user.admin,
      userType: user && user.userType,
    })
    //console.log('我',this.data.name,this.data.admin,this.data.userType)
    //如果用户时医生的话，根据admin得到doctorId
    if(user.userType=="B"){
      wx.cloud.callFunction({
        name:'doctorInfo',
        data:{
          action:'findOne',
          userDoctorAdmin:user.admin
        }
      }).then(res=>{
        console.log('获取医生信息成功',res)
        that.setData({
          doctorId:res.result.data[0].doctorId
        })
      })
    }
  },
  out() {
    console.log("退出小程序")
    wx.navigateTo({
      url: '/pages/login/login',
    })
    wx.setStorageSync('user', null)
    setTimeout(() => {
      wx.showToast({
        title: '退出成功',
      })
    }, 1000);
  }
})